//
//  DataParsing.m
//  项目A
//
//  Created by lanou3g on 15/8/31.
//  Copyright (c) 2015年 王钧. All rights reserved.
//

#import "DataParsing.h"

@implementation DataParsing

+ (void)DataUrl:(NSString *)SURL andMethod:(NSString *)method andBody:(NSString *)body andBlock:(DataBlock)block
{
    //1.生成url
    NSURL *url = [NSURL URLWithString:SURL];
    
    //2.生成请求对象
    NSMutableURLRequest *request  =[[NSMutableURLRequest alloc]initWithURL:url];
    //判断请求方式如果是POST，生成body
    if ([@"POST" isEqualToString:method]) {
        [request setHTTPMethod:@"POST"];
        NSData *param = [body dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:param];
    }
    
    //3.发送数据请求，获取数据
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        //4.调用block进行数据处理
        block(data);
    }];
}

@end
